Skip to content

FIX Bug when targeting an nn.Parameter on the root module#3302

Open
BenjaminBossan wants to merge 1 commit into
huggingface:mainfrom
BenjaminBossan:fix-target-parameter-on-top-level
Open

FIX Bug when targeting an nn.Parameter on the root module#3302
BenjaminBossan wants to merge 1 commit into
huggingface:mainfrom
BenjaminBossan:fix-target-parameter-on-top-level

Conversation

@BenjaminBossan

Copy link
Copy Markdown
Member

Using LoRA, we allow to target nn.Parameters directly by using target_parametes=[...]. This works by replacing the module that this parameter belongs to with lora.ParamWrapper. However, this cannot work if the parameter lives on the root model itself, since that would require replacing the whole model. What actually happened was that the module would self-reference, leading to an infinite recursion. With this fix, we now detect this degenerate case and raise a proper error.

Note that I discovered this only by accident while working on a test with a dummy model. It should be extremely unlikely that any real world use cases would require targeting a parameter on the root model. If we get such reports, we can think about a better solution.

Using LoRA, we allow to target nn.Parameters directly by using
target_parametes=[...]. This works by replacing the module that this
parameter belongs to with lora.ParamWrapper. However, this cannot work
if the parameter lives on the root model itself, since that would
require replacing the whole model. What actually happened was that the
module would self-reference, leading to an infinite recursion. With
this fix, we now detect this degenerate case and raise a proper error.

Note that I discovered this only by accident while working on a test
with a dummy model. It should be extremely unlikely that any real
world use cases would require targeting a parameter on the root
model. If we get such reports, we can think about a better solution.
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@BenjaminBossan BenjaminBossan requested a review from githubnemo June 5, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants